package com.zhongjian.technologycal.mall.activity.personal.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.adapter.DockingExpandableListViewAdapter;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.utils.StatusBarUtil;
import com.zhongjian.technologycal.mall.view.ConDockingAdapterDataSource;
import com.zhongjian.technologycal.mall.view.DockingExpandableListView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by wei on 2017/12/25.
 */

public class CashRecordActivity extends BaseActivity {
    @BindView(R.id.tv_main_title)
    TextView tv_main_title;
    @BindView(R.id.docking_list_view)
    DockingExpandableListView listView;

    @Override
    protected void beforeInit() {
        super.beforeInit();
//        StatusBarUtil.setColorNoTranslucent(this, getResources().getColor(R.color.border_color));
//        StatusBarUtil.setMiuiStatusBarDarkMode(this, true);
    }
    @Override
    public void initPresenter() {

    }
    @Override
    protected void initView(Bundle savedInstanceState) {
        tv_main_title.setText("现金币记录");

        ConDockingAdapterDataSource listData = prepareData();
        listView.setGroupIndicator(null);
        listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        listView.setAdapter(new DockingExpandableListViewAdapter(this, listView, listData));
        for (int i = 0; i < listData.getGroupCount(); i++) {
            listView.expandGroup(i);
        }
        listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                if (parent.isGroupExpanded(groupPosition)) {
                    parent.collapseGroup(groupPosition);
                } else {
                    parent.expandGroup(groupPosition);
                }

                return true;
            }
        });
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                return false;
            }
        });

        View headerView = getLayoutInflater().inflate(R.layout.group_view_item, listView, false);
//        listView.setDockingHeader(headerView, new IDockingHeaderUpdateListener() {
//            @Override
//            public void onUpdate(View headerView, int groupPosition, boolean expanded) {
//                String groupTitle = "本周" + String.valueOf(groupPosition + 1);
//                TextView titleView = (TextView) headerView.findViewById(R.id.group_view_title);
//                titleView.setText(groupTitle);
//            }
//        });
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_cash_record;
    }

    @OnClick(R.id.iv_back_page)
    public void onClickBack() {
        finish();
    }

    private ConDockingAdapterDataSource prepareData() {
        ConDockingAdapterDataSource listData
                = new ConDockingAdapterDataSource(this);


        listData.addGroup("本周")
                .addChild("Dish #1")
                .addChild("Dish #2")
                .addChild("Dish #3")
                .addChild("Dish #4")
                .addGroup("12月")
                .addChild("Drink #1")
                .addChild("Drink #2")
                .addChild("Drink #3")
                .addChild("Drink #4")
                .addChild("Drink #5")
                .addChild("Drink #6")
                .addChild("Drink #7")
                .addChild("Drink #8")
                .addChild("Drink #9")
                .addGroup("Group #3")
                .addChild("Dessert #1")
                .addChild("Dessert #2")
                .addChild("Dessert #3")
                .addChild("Dessert #4")
                .addChild("Dessert #5")
                .addChild("Dessert #6")
                .addChild("Dessert #7")
                .addChild("Dessert #8");

        return listData;
    }
}
